<template>
  <div>
    <div class="bgfff mtrbl20 ptrbl20 nopb20">
    <div>
        <div class="apptitle">{{ appName }}</div>
        <el-row :gutter="20" class="appInfoTips">
          <el-col :span="5" :xs="24">
            <div>APPID：{{ appId }}</div>
            <div>用户人数：{{ userCount }}</div>
          </el-col>
          <el-col :span="5" :xs="24">
            <div>所属企业：{{ companyName }}</div>
            <div>创建时间：{{ createTime }}</div>
          </el-col>
          <el-col :span="8" :xs="24">
            <div>上传安全域名文档：{{ txtKeyText }} 
                <el-button size="mini" type="text" @click="handleDownload(txtKey)">下载文件</el-button>
            </div>
          </el-col>
          <el-col :span="6" :xs="24">
             <div>域名配置：{{ buildStatus == 1 ? '已配置' : '未配置' }}</div>
          </el-col>
        </el-row>
    </div>
    </div>
    <div class="app-container">  
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="openId" prop="openId">
            <el-input
              v-model="queryParams.openId"
              placeholder="请输入openId"
              clearable
              size="medium"
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="真实姓名" prop="realName">
            <el-input
              v-model="queryParams.realName"
              placeholder="请输入真实姓名"
              clearable
              size="medium"
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="证件号" prop="idNumber">
            <el-input
              v-model="queryParams.idNumber"
              placeholder="请输入证件号"
              clearable
              size="medium"
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
           <el-form-item label="手机号码" prop="phone">
            <el-input
              v-model="queryParams.phone"
              placeholder="请输入手机号码"
              clearable
              size="medium"
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="medium" @click="resetQuery">重置</el-button>
            <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="medium"
            v-hasPermi="['offiaccount:public:detailExport']"
            @click="handleBatchExport"
          >批量导出</el-button>
          </el-form-item>
        </el-form>
        </el-col>
        </el-row>
      
        <el-row :gutter="20">
          <!--用户数据-->
          <el-col :span="24" :xs="24">
          <el-table v-loading="loading" :data="offiaccountListDetail">
          
          <el-table-column label="序号" prop="" width="55" align="center">
            <template slot-scope="scope">
              <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column label="openId" align="left" key="openId" prop="openId"/>
          <el-table-column label="真实姓名" align="left" key="realName" prop="realName"/>
          <el-table-column label="证件号" align="left" key="idNumber" prop="idNumber"/>
          <el-table-column label="手机号" align="left" key="phone" prop="phone" />
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
  </div>
  </div>
</template>

<script>
import { offiaccountListDetail,offiaccountExport } from "@/api/offiaccount/public";
export default {
  name: "PublicDetails",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      offiaccountListDetail: null,
      // 查询参数
      appName:'',
      appId: '',
      userCount: '',
      companyName: '',
      createTime: '',
      buildStatus: '',
      txtKey:'',
      txtKeyText:'',
      queryParams: {
        id: this.$route.params.id,
        appId: this.$route.params.appid, 
        pageNum: 1,
        pageSize: 20,
        openId: undefined,
        realName: undefined,
        idNumber: undefined,
        phone: undefined
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      offiaccountListDetail(this.queryParams).then(response => {
          this.offiaccountListDetail = response.data.userList.list;
          this.total = response.data.userList.total;

          this.appName = response.data.appName;
          this.appId = response.data.appId;
          this.userCount = response.data.userCount;
          this.companyName = response.data.companyName;
          this.createTime = response.data.createTime;
          this.buildStatus = response.data.buildStatus;

          this.txtKey = response.data.txtKey;
          let str = response.data.txtKey;
          let arr = str.split('/');
          let len =arr.length;
          let name = arr[len-1];
          this.txtKeyText = name ;

          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      //this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleBatchExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return offiaccountExport(queryParams);
        }).then(response => {
          var list_name = "公众号用户列表";
          this.export_excel_file(response, list_name);
        }).catch(()=>{})
    },
    handleDownload(txtKey) {
      this.getBackendOssAliyunSts(txtKey);
    },
  }
};
</script>
<style scoped lang="scss">
.apptitle{
  font-size: 20px;
  font-weight: bold;
  color: #333;
  padding-bottom: 10px;
}
.appInfoTips{
  font-size: 14px;
  color: #999;
  padding-bottom: 20px;
}
.appInfoTips div{
  line-height: 30px;
}
</style>